{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 复习\n",
    "\n",
    "* 收益率，连续收益率，单期收益率与多期收益率的关系\n",
    "\n",
    "* 风险,夏普率"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 掘金多股价数据处理-数据变形与空值处理\n",
    "\n",
    "https://blog.csdn.net/qq_17753903/article/details/89892631"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  \n",
    "import matplotlib.pyplot as plt  \n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gm.api import *\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "set_token(\"eea4b28a3ceb7048603d388bb777ebc67de47385\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>high</th>\n",
       "      <th>eob</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>14.7448</td>\n",
       "      <td>15.0698</td>\n",
       "      <td>14.5070</td>\n",
       "      <td>15.3473</td>\n",
       "      <td>2015-01-05 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SZSE.000002</td>\n",
       "      <td>10.9058</td>\n",
       "      <td>11.2999</td>\n",
       "      <td>10.7770</td>\n",
       "      <td>11.5879</td>\n",
       "      <td>2015-01-05 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SZSE.000001</td>\n",
       "      <td>10.1555</td>\n",
       "      <td>10.1745</td>\n",
       "      <td>9.9078</td>\n",
       "      <td>10.3396</td>\n",
       "      <td>2015-01-05 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>10.0151</td>\n",
       "      <td>9.9189</td>\n",
       "      <td>9.7445</td>\n",
       "      <td>10.0693</td>\n",
       "      <td>2015-01-05 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>14.9826</td>\n",
       "      <td>15.9418</td>\n",
       "      <td>14.8637</td>\n",
       "      <td>16.1558</td>\n",
       "      <td>2015-01-06 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1176</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>13.5467</td>\n",
       "      <td>13.6924</td>\n",
       "      <td>13.5103</td>\n",
       "      <td>14.0841</td>\n",
       "      <td>2015-12-30 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1177</th>\n",
       "      <td>SZSE.000413</td>\n",
       "      <td>8.8681</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>8.9448</td>\n",
       "      <td>2015-12-31 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1178</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>18.3058</td>\n",
       "      <td>17.8835</td>\n",
       "      <td>17.8739</td>\n",
       "      <td>18.3058</td>\n",
       "      <td>2015-12-31 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1179</th>\n",
       "      <td>SZSE.000001</td>\n",
       "      <td>9.3036</td>\n",
       "      <td>9.2190</td>\n",
       "      <td>9.2113</td>\n",
       "      <td>9.3267</td>\n",
       "      <td>2015-12-31 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1180</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>13.6621</td>\n",
       "      <td>13.3585</td>\n",
       "      <td>13.3069</td>\n",
       "      <td>13.7805</td>\n",
       "      <td>2015-12-31 00:00:00+08:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1181 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           symbol     open    close      low     high  \\\n",
       "0     SZSE.000063  14.7448  15.0698  14.5070  15.3473   \n",
       "1     SZSE.000002  10.9058  11.2999  10.7770  11.5879   \n",
       "2     SZSE.000001  10.1555  10.1745   9.9078  10.3396   \n",
       "3     SZSE.002007  10.0151   9.9189   9.7445  10.0693   \n",
       "4     SZSE.000063  14.9826  15.9418  14.8637  16.1558   \n",
       "...           ...      ...      ...      ...      ...   \n",
       "1176  SZSE.002007  13.5467  13.6924  13.5103  14.0841   \n",
       "1177  SZSE.000413   8.8681   8.7051   8.7051   8.9448   \n",
       "1178  SZSE.000063  18.3058  17.8835  17.8739  18.3058   \n",
       "1179  SZSE.000001   9.3036   9.2190   9.2113   9.3267   \n",
       "1180  SZSE.002007  13.6621  13.3585  13.3069  13.7805   \n",
       "\n",
       "                           eob  \n",
       "0    2015-01-05 00:00:00+08:00  \n",
       "1    2015-01-05 00:00:00+08:00  \n",
       "2    2015-01-05 00:00:00+08:00  \n",
       "3    2015-01-05 00:00:00+08:00  \n",
       "4    2015-01-06 00:00:00+08:00  \n",
       "...                        ...  \n",
       "1176 2015-12-30 00:00:00+08:00  \n",
       "1177 2015-12-31 00:00:00+08:00  \n",
       "1178 2015-12-31 00:00:00+08:00  \n",
       "1179 2015-12-31 00:00:00+08:00  \n",
       "1180 2015-12-31 00:00:00+08:00  \n",
       "\n",
       "[1181 rows x 6 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#000413 东旭光电，000063 中兴通讯，002007 华兰生物，000001 平安银行，000002 万科A\n",
    "stock_n = history(symbol='SZSE.000413,SZSE.000063,SZSE.002007,SZSE.000001,SZSE.000002', frequency='1d', start_time='2015-01-01',  end_time='2015-12-31', fields='symbol,open, close, low, high, eob', adjust=ADJUST_PREV, df= True)\n",
    "stock_n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def time_str(x):\n",
    "    return str(x.date())\n",
    "\n",
    "stock_n.eob=stock_n.eob.apply(time_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>high</th>\n",
       "      <th>eob</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>14.7448</td>\n",
       "      <td>15.0698</td>\n",
       "      <td>14.5070</td>\n",
       "      <td>15.3473</td>\n",
       "      <td>2015-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SZSE.000002</td>\n",
       "      <td>10.9058</td>\n",
       "      <td>11.2999</td>\n",
       "      <td>10.7770</td>\n",
       "      <td>11.5879</td>\n",
       "      <td>2015-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SZSE.000001</td>\n",
       "      <td>10.1555</td>\n",
       "      <td>10.1745</td>\n",
       "      <td>9.9078</td>\n",
       "      <td>10.3396</td>\n",
       "      <td>2015-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>10.0151</td>\n",
       "      <td>9.9189</td>\n",
       "      <td>9.7445</td>\n",
       "      <td>10.0693</td>\n",
       "      <td>2015-01-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>14.9826</td>\n",
       "      <td>15.9418</td>\n",
       "      <td>14.8637</td>\n",
       "      <td>16.1558</td>\n",
       "      <td>2015-01-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1176</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>13.5467</td>\n",
       "      <td>13.6924</td>\n",
       "      <td>13.5103</td>\n",
       "      <td>14.0841</td>\n",
       "      <td>2015-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1177</th>\n",
       "      <td>SZSE.000413</td>\n",
       "      <td>8.8681</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>8.9448</td>\n",
       "      <td>2015-12-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1178</th>\n",
       "      <td>SZSE.000063</td>\n",
       "      <td>18.3058</td>\n",
       "      <td>17.8835</td>\n",
       "      <td>17.8739</td>\n",
       "      <td>18.3058</td>\n",
       "      <td>2015-12-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1179</th>\n",
       "      <td>SZSE.000001</td>\n",
       "      <td>9.3036</td>\n",
       "      <td>9.2190</td>\n",
       "      <td>9.2113</td>\n",
       "      <td>9.3267</td>\n",
       "      <td>2015-12-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1180</th>\n",
       "      <td>SZSE.002007</td>\n",
       "      <td>13.6621</td>\n",
       "      <td>13.3585</td>\n",
       "      <td>13.3069</td>\n",
       "      <td>13.7805</td>\n",
       "      <td>2015-12-31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1181 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           symbol     open    close      low     high         eob\n",
       "0     SZSE.000063  14.7448  15.0698  14.5070  15.3473  2015-01-05\n",
       "1     SZSE.000002  10.9058  11.2999  10.7770  11.5879  2015-01-05\n",
       "2     SZSE.000001  10.1555  10.1745   9.9078  10.3396  2015-01-05\n",
       "3     SZSE.002007  10.0151   9.9189   9.7445  10.0693  2015-01-05\n",
       "4     SZSE.000063  14.9826  15.9418  14.8637  16.1558  2015-01-06\n",
       "...           ...      ...      ...      ...      ...         ...\n",
       "1176  SZSE.002007  13.5467  13.6924  13.5103  14.0841  2015-12-30\n",
       "1177  SZSE.000413   8.8681   8.7051   8.7051   8.9448  2015-12-31\n",
       "1178  SZSE.000063  18.3058  17.8835  17.8739  18.3058  2015-12-31\n",
       "1179  SZSE.000001   9.3036   9.2190   9.2113   9.3267  2015-12-31\n",
       "1180  SZSE.002007  13.6621  13.3585  13.3069  13.7805  2015-12-31\n",
       "\n",
       "[1181 rows x 6 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>10.1745</td>\n",
       "      <td>11.2999</td>\n",
       "      <td>15.0698</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.9189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>10.0221</td>\n",
       "      <td>10.8831</td>\n",
       "      <td>15.9418</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.4331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>9.8316</td>\n",
       "      <td>10.7845</td>\n",
       "      <td>15.6247</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.2436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>9.5013</td>\n",
       "      <td>10.2995</td>\n",
       "      <td>15.8467</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.4541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>9.5775</td>\n",
       "      <td>10.1934</td>\n",
       "      <td>15.4979</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.3369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>9.5420</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18.2482</td>\n",
       "      <td>8.9640</td>\n",
       "      <td>13.2643</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>9.2113</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.6243</td>\n",
       "      <td>8.6668</td>\n",
       "      <td>13.0184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>9.2959</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.8643</td>\n",
       "      <td>8.7914</td>\n",
       "      <td>13.5467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>9.3036</td>\n",
       "      <td>NaN</td>\n",
       "      <td>18.3826</td>\n",
       "      <td>8.9064</td>\n",
       "      <td>13.6924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>9.2190</td>\n",
       "      <td>NaN</td>\n",
       "      <td>17.8835</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>13.3585</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>244 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-05      10.1745      11.2999      15.0698          NaN       9.9189\n",
       "2015-01-06      10.0221      10.8831      15.9418          NaN      10.4331\n",
       "2015-01-07       9.8316      10.7845      15.6247          NaN      10.2436\n",
       "2015-01-08       9.5013      10.2995      15.8467          NaN      10.4541\n",
       "2015-01-09       9.5775      10.1934      15.4979          NaN      10.3369\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       9.5420          NaN      18.2482       8.9640      13.2643\n",
       "2015-12-28       9.2113          NaN      17.6243       8.6668      13.0184\n",
       "2015-12-29       9.2959          NaN      17.8643       8.7914      13.5467\n",
       "2015-12-30       9.3036          NaN      18.3826       8.9064      13.6924\n",
       "2015-12-31       9.2190          NaN      17.8835       8.7051      13.3585\n",
       "\n",
       "[244 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_close=pd.pivot_table(stock_n,index=[\"eob\"],columns=[\"symbol\"],values=[\"close\"]).close\n",
    "stock_close"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "#help(stock_close.fillna)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=stock_close.fillna(axis=0,method='ffill')\n",
    "data.fillna(axis=0,method='bfill',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>10.1745</td>\n",
       "      <td>11.2999</td>\n",
       "      <td>15.0698</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>9.9189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>10.0221</td>\n",
       "      <td>10.8831</td>\n",
       "      <td>15.9418</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.4331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>9.8316</td>\n",
       "      <td>10.7845</td>\n",
       "      <td>15.6247</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.2436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>9.5013</td>\n",
       "      <td>10.2995</td>\n",
       "      <td>15.8467</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.4541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>9.5775</td>\n",
       "      <td>10.1934</td>\n",
       "      <td>15.4979</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.3369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>9.5420</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>18.2482</td>\n",
       "      <td>8.9640</td>\n",
       "      <td>13.2643</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>9.2113</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.6243</td>\n",
       "      <td>8.6668</td>\n",
       "      <td>13.0184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>9.2959</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.8643</td>\n",
       "      <td>8.7914</td>\n",
       "      <td>13.5467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>9.3036</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>18.3826</td>\n",
       "      <td>8.9064</td>\n",
       "      <td>13.6924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>9.2190</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.8835</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>13.3585</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>244 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-05      10.1745      11.2999      15.0698       8.0181       9.9189\n",
       "2015-01-06      10.0221      10.8831      15.9418       8.0181      10.4331\n",
       "2015-01-07       9.8316      10.7845      15.6247       8.0181      10.2436\n",
       "2015-01-08       9.5013      10.2995      15.8467       8.0181      10.4541\n",
       "2015-01-09       9.5775      10.1934      15.4979       8.0181      10.3369\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       9.5420      19.1382      18.2482       8.9640      13.2643\n",
       "2015-12-28       9.2113      19.1382      17.6243       8.6668      13.0184\n",
       "2015-12-29       9.2959      19.1382      17.8643       8.7914      13.5467\n",
       "2015-12-30       9.3036      19.1382      18.3826       8.9064      13.6924\n",
       "2015-12-31       9.2190      19.1382      17.8835       8.7051      13.3585\n",
       "\n",
       "[244 rows x 5 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 多股票收益率计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>10.1745</td>\n",
       "      <td>11.2999</td>\n",
       "      <td>15.0698</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>9.9189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>10.0221</td>\n",
       "      <td>10.8831</td>\n",
       "      <td>15.9418</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.4331</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>9.8316</td>\n",
       "      <td>10.7845</td>\n",
       "      <td>15.6247</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.2436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>9.5013</td>\n",
       "      <td>10.2995</td>\n",
       "      <td>15.8467</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.4541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>9.5775</td>\n",
       "      <td>10.1934</td>\n",
       "      <td>15.4979</td>\n",
       "      <td>8.0181</td>\n",
       "      <td>10.3369</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>9.5420</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>18.2482</td>\n",
       "      <td>8.9640</td>\n",
       "      <td>13.2643</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>9.2113</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.6243</td>\n",
       "      <td>8.6668</td>\n",
       "      <td>13.0184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>9.2959</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.8643</td>\n",
       "      <td>8.7914</td>\n",
       "      <td>13.5467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>9.3036</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>18.3826</td>\n",
       "      <td>8.9064</td>\n",
       "      <td>13.6924</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>9.2190</td>\n",
       "      <td>19.1382</td>\n",
       "      <td>17.8835</td>\n",
       "      <td>8.7051</td>\n",
       "      <td>13.3585</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>244 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-05      10.1745      11.2999      15.0698       8.0181       9.9189\n",
       "2015-01-06      10.0221      10.8831      15.9418       8.0181      10.4331\n",
       "2015-01-07       9.8316      10.7845      15.6247       8.0181      10.2436\n",
       "2015-01-08       9.5013      10.2995      15.8467       8.0181      10.4541\n",
       "2015-01-09       9.5775      10.1934      15.4979       8.0181      10.3369\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       9.5420      19.1382      18.2482       8.9640      13.2643\n",
       "2015-12-28       9.2113      19.1382      17.6243       8.6668      13.0184\n",
       "2015-12-29       9.2959      19.1382      17.8643       8.7914      13.5467\n",
       "2015-12-30       9.3036      19.1382      18.3826       8.9064      13.6924\n",
       "2015-12-31       9.2190      19.1382      17.8835       8.7051      13.3585\n",
       "\n",
       "[244 rows x 5 columns]"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0150</td>\n",
       "      <td>-0.0369</td>\n",
       "      <td>0.0579</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0190</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0199</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.0182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0336</td>\n",
       "      <td>-0.0450</td>\n",
       "      <td>0.0142</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0103</td>\n",
       "      <td>-0.0220</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.0112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>-0.0206</td>\n",
       "      <td>-0.0245</td>\n",
       "      <td>-0.0210</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0209</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-06      -0.0150      -0.0369       0.0579          0.0       0.0518\n",
       "2015-01-07      -0.0190      -0.0091      -0.0199          0.0      -0.0182\n",
       "2015-01-08      -0.0336      -0.0450       0.0142          0.0       0.0205\n",
       "2015-01-09       0.0080      -0.0103      -0.0220          0.0      -0.0112\n",
       "2015-01-12      -0.0206      -0.0245      -0.0210          0.0       0.0209"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r=(data/data.shift(1)-1).dropna()\n",
    "\n",
    "r.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r_p[\"000413.XSHE\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 资产风险的测度\n",
    "\n",
    "\n",
    "https://blog.csdn.net/weixin_42219751/article/details/94391315\n",
    "\n",
    "### 方差\n",
    "\n",
    "## 夏普率\n",
    "\n",
    "夏普率(sharpe ratio): 衡量策略相对于无风险组合的表现，是策略所获得风险溢价的度量——即如果策略额外承担一单位的风险，可以获得多少单位的收益作为补偿。\n",
    "\n",
    "https://www.ricequant.com/doc/api/python/chn#backtest-results-factors\n",
    "\n",
    "https://wiki.mbalib.com/wiki/%E5%A4%8F%E6%99%AE%E6%8C%87%E6%95%B0\n",
    "\n",
    "\n",
    "### 连续收益率\n",
    "\n",
    "* 和一般收益率一一对应\n",
    "* 多期等于单期之和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## classwork1\n",
    "\n",
    "* 请计算SZSE.002007的年度夏普率\n",
    "* 请计算各个股票各天的日收益率，日连续收益率（np.log），年化连续收益率（sum）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2977048164153988"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log(data[\"SZSE.002007\"][-1])-np.log(data[\"SZSE.002007\"][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "symbol\n",
       "SZSE.000001   -0.0986\n",
       "SZSE.000002    0.5269\n",
       "SZSE.000063    0.1712\n",
       "SZSE.000413    0.0822\n",
       "SZSE.002007    0.2977\n",
       "dtype: float64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0151</td>\n",
       "      <td>-0.0376</td>\n",
       "      <td>0.0563</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0192</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0201</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0342</td>\n",
       "      <td>-0.0460</td>\n",
       "      <td>0.0141</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0104</td>\n",
       "      <td>-0.0223</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>-0.0208</td>\n",
       "      <td>-0.0248</td>\n",
       "      <td>-0.0212</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>0.0057</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0058</td>\n",
       "      <td>-0.0043</td>\n",
       "      <td>-0.0057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>-0.0353</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0348</td>\n",
       "      <td>-0.0337</td>\n",
       "      <td>-0.0187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0135</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0286</td>\n",
       "      <td>0.0130</td>\n",
       "      <td>0.0107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>-0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0275</td>\n",
       "      <td>-0.0229</td>\n",
       "      <td>-0.0247</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>243 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-06      -0.0151      -0.0376       0.0563       0.0000       0.0505\n",
       "2015-01-07      -0.0192      -0.0091      -0.0201       0.0000      -0.0183\n",
       "2015-01-08      -0.0342      -0.0460       0.0141       0.0000       0.0203\n",
       "2015-01-09       0.0080      -0.0104      -0.0223       0.0000      -0.0113\n",
       "2015-01-12      -0.0208      -0.0248      -0.0212       0.0000       0.0207\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       0.0057       0.0000       0.0058      -0.0043      -0.0057\n",
       "2015-12-28      -0.0353       0.0000      -0.0348      -0.0337      -0.0187\n",
       "2015-12-29       0.0091       0.0000       0.0135       0.0143       0.0398\n",
       "2015-12-30       0.0008       0.0000       0.0286       0.0130       0.0107\n",
       "2015-12-31      -0.0091       0.0000      -0.0275      -0.0229      -0.0247\n",
       "\n",
       "[243 rows x 5 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0151</td>\n",
       "      <td>-0.0376</td>\n",
       "      <td>0.0563</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0192</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0201</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0342</td>\n",
       "      <td>-0.0460</td>\n",
       "      <td>0.0141</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0104</td>\n",
       "      <td>-0.0223</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>-0.0208</td>\n",
       "      <td>-0.0248</td>\n",
       "      <td>-0.0212</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>0.0057</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0058</td>\n",
       "      <td>-0.0043</td>\n",
       "      <td>-0.0057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>-0.0353</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0348</td>\n",
       "      <td>-0.0337</td>\n",
       "      <td>-0.0187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0135</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0286</td>\n",
       "      <td>0.0130</td>\n",
       "      <td>0.0107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>-0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0275</td>\n",
       "      <td>-0.0229</td>\n",
       "      <td>-0.0247</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>243 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-06      -0.0151      -0.0376       0.0563       0.0000       0.0505\n",
       "2015-01-07      -0.0192      -0.0091      -0.0201       0.0000      -0.0183\n",
       "2015-01-08      -0.0342      -0.0460       0.0141       0.0000       0.0203\n",
       "2015-01-09       0.0080      -0.0104      -0.0223       0.0000      -0.0113\n",
       "2015-01-12      -0.0208      -0.0248      -0.0212       0.0000       0.0207\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       0.0057       0.0000       0.0058      -0.0043      -0.0057\n",
       "2015-12-28      -0.0353       0.0000      -0.0348      -0.0337      -0.0187\n",
       "2015-12-29       0.0091       0.0000       0.0135       0.0143       0.0398\n",
       "2015-12-30       0.0008       0.0000       0.0286       0.0130       0.0107\n",
       "2015-12-31      -0.0091       0.0000      -0.0275      -0.0229      -0.0247\n",
       "\n",
       "[243 rows x 5 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log=(np.log(data)-np.log(data.shift(1))).dropna()\n",
    "r_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.45423011739554886"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[\"SZSE.002007\"].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "eob\n",
       "2015-01-05     9.9189\n",
       "2015-01-06    10.4331\n",
       "2015-01-07    10.2436\n",
       "2015-01-08    10.4541\n",
       "2015-01-09    10.3369\n",
       "               ...   \n",
       "2015-12-25    13.2643\n",
       "2015-12-28    13.0184\n",
       "2015-12-29    13.5467\n",
       "2015-12-30    13.6924\n",
       "2015-12-31    13.3585\n",
       "Name: SZSE.002007, Length: 244, dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[\"SZSE.002007\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3467641865195543"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_n=data[\"SZSE.002007\"][-1]/data[\"SZSE.002007\"][0]-1\n",
    "r_n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.68677622218379"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_n/r[\"SZSE.002007\"].std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.03579768733847964"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[\"SZSE.002007\"].std()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 投资组合的收益率与风险"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0150</td>\n",
       "      <td>-0.0369</td>\n",
       "      <td>0.0579</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0190</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0199</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0336</td>\n",
       "      <td>-0.0450</td>\n",
       "      <td>0.0142</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0103</td>\n",
       "      <td>-0.0220</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>-0.0206</td>\n",
       "      <td>-0.0245</td>\n",
       "      <td>-0.0210</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>0.0057</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0058</td>\n",
       "      <td>-0.0043</td>\n",
       "      <td>-0.0057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>-0.0346</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0342</td>\n",
       "      <td>-0.0332</td>\n",
       "      <td>-0.0185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>0.0092</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0136</td>\n",
       "      <td>0.0144</td>\n",
       "      <td>0.0406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0290</td>\n",
       "      <td>0.0131</td>\n",
       "      <td>0.0108</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>-0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0272</td>\n",
       "      <td>-0.0226</td>\n",
       "      <td>-0.0244</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>243 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-06      -0.0150      -0.0369       0.0579       0.0000       0.0518\n",
       "2015-01-07      -0.0190      -0.0091      -0.0199       0.0000      -0.0182\n",
       "2015-01-08      -0.0336      -0.0450       0.0142       0.0000       0.0205\n",
       "2015-01-09       0.0080      -0.0103      -0.0220       0.0000      -0.0112\n",
       "2015-01-12      -0.0206      -0.0245      -0.0210       0.0000       0.0209\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       0.0057       0.0000       0.0058      -0.0043      -0.0057\n",
       "2015-12-28      -0.0346       0.0000      -0.0342      -0.0332      -0.0185\n",
       "2015-12-29       0.0092       0.0000       0.0136       0.0144       0.0406\n",
       "2015-12-30       0.0008       0.0000       0.0290       0.0131       0.0108\n",
       "2015-12-31      -0.0091       0.0000      -0.0272      -0.0226      -0.0244\n",
       "\n",
       "[243 rows x 5 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.72584472, 0.48109393, 0.85143572, 0.30861401, 0.21165816])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#随机生成投资组合的权重\n",
    "weights = np.random.random(5)\n",
    "\n",
    "weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.28148283, 0.18656839, 0.33018706, 0.11968062, 0.0820811 ])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weights = weights/np.sum(weights)\n",
    "\n",
    "weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.28148283, 0.18656839, 0.33018706, 0.11968062, 0.0820811 ])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "2015-01-06\t-0.0150\t-0.0369\t0.0579\t0.0000\t0.0518"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.012263015712999998"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.28148283*(-0.0150)+0.18656839*(-0.0369)+0.33018706*0.0579+0+0.0820811*0.0518"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights=np.array([ 0.37505798, 0.21652754, 0.31590981, 0.06087709, 0.03162758])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 组合收益率与点乘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weights"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02568078242639"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.1484967*0+0.25120513*(-0.014977)+0.29997291*0.057862+0.26109273*0.051833+0.03923253*(-0.036887)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "symbol\n",
       "SZSE.000001   -0.0150\n",
       "SZSE.000002   -0.0369\n",
       "SZSE.000063    0.0579\n",
       "SZSE.000413    0.0000\n",
       "SZSE.002007    0.0518\n",
       "Name: 2015-01-06, dtype: float64"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.loc[\"2015-01-06\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.28148283, 0.18656839, 0.33018706, 0.11968062, 0.0820811 ])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weights*r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0244154154845"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.15716611*0+0.29939866*0.057980+0.24037151*0.052000-0.25762955*0.014634-0.04543418*0.036820"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0151</td>\n",
       "      <td>-0.0376</td>\n",
       "      <td>0.0563</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0192</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0201</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0342</td>\n",
       "      <td>-0.0460</td>\n",
       "      <td>0.0141</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0104</td>\n",
       "      <td>-0.0223</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>0.0057</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0058</td>\n",
       "      <td>-0.0043</td>\n",
       "      <td>-0.0057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>-0.0353</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0348</td>\n",
       "      <td>-0.0337</td>\n",
       "      <td>-0.0187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0135</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0286</td>\n",
       "      <td>0.0130</td>\n",
       "      <td>0.0107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>-0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0275</td>\n",
       "      <td>-0.0229</td>\n",
       "      <td>-0.0247</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>244 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-05          NaN          NaN          NaN          NaN          NaN\n",
       "2015-01-06      -0.0151      -0.0376       0.0563       0.0000       0.0505\n",
       "2015-01-07      -0.0192      -0.0091      -0.0201       0.0000      -0.0183\n",
       "2015-01-08      -0.0342      -0.0460       0.0141       0.0000       0.0203\n",
       "2015-01-09       0.0080      -0.0104      -0.0223       0.0000      -0.0113\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       0.0057       0.0000       0.0058      -0.0043      -0.0057\n",
       "2015-12-28      -0.0353       0.0000      -0.0348      -0.0337      -0.0187\n",
       "2015-12-29       0.0091       0.0000       0.0135       0.0143       0.0398\n",
       "2015-12-30       0.0008       0.0000       0.0286       0.0130       0.0107\n",
       "2015-12-31      -0.0091       0.0000      -0.0275      -0.0229      -0.0247\n",
       "\n",
       "[244 rows x 5 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.14605053e-02, -1.52373654e-02, -1.18764692e-02, -7.95788007e-03,\n",
       "       -1.57784364e-02,  5.53741940e-04,  1.32390638e-03,  2.61761237e-02,\n",
       "       -4.78853354e-04, -8.13959342e-02,  2.58628988e-02,  3.37232029e-02,\n",
       "        5.57798856e-03,  6.80100958e-03,  7.43689542e-03, -2.07065983e-02,\n",
       "       -7.20864567e-03, -1.09893181e-02, -6.31743008e-03, -2.12878943e-02,\n",
       "        1.82162151e-02, -2.02139558e-02, -2.02574219e-03, -2.59680526e-02,\n",
       "        4.41794255e-03,  1.72557876e-02,  1.67286730e-02,  1.98573679e-03,\n",
       "        1.18704626e-02,  1.80739666e-02, -3.98790846e-03, -2.06441150e-02,\n",
       "        1.94221604e-02,  6.05077894e-03,  8.76116075e-03, -2.14269824e-02,\n",
       "        1.01796460e-02, -2.22556687e-03,  4.17822018e-03,  2.18264839e-02,\n",
       "       -1.12092481e-02, -5.98808146e-04,  1.45532800e-02,  1.45583975e-02,\n",
       "        2.41227410e-02,  1.86302460e-02,  1.94755507e-02, -1.44278227e-02,\n",
       "        1.12342501e-02,  1.92641927e-02,  2.39101646e-03, -1.22785280e-02,\n",
       "       -3.89908753e-03,  4.48895731e-03,  3.01040254e-02, -1.06450486e-02,\n",
       "        1.87931558e-02, -4.40065440e-03, -3.77542991e-03,  3.70177460e-02,\n",
       "        3.41645344e-02,  4.86057172e-03,  3.21691492e-02,  1.35610922e-02,\n",
       "       -2.01305947e-02, -8.15050639e-03,  3.03728005e-02,  1.72016009e-02,\n",
       "       -1.24502112e-02,  3.21567214e-02,  1.67870259e-02,  8.37340094e-03,\n",
       "       -1.29491702e-02,  1.32502570e-02, -2.24410879e-02,  3.52407036e-02,\n",
       "        7.22640406e-03, -1.10171272e-02, -5.02852578e-02, -1.41877501e-02,\n",
       "       -1.23274862e-03,  2.89709420e-02,  2.05676048e-02,  1.34718789e-03,\n",
       "        2.80980114e-02, -4.30097306e-03, -2.81969074e-02,  4.81023027e-03,\n",
       "        1.98367436e-02,  4.93995949e-03,  1.66340141e-02,  1.36119715e-02,\n",
       "        2.82434776e-02,  1.77038883e-02, -3.89036380e-03, -7.43059698e-02,\n",
       "       -6.58159623e-03,  3.98094436e-02,  9.13687374e-03, -8.92485881e-03,\n",
       "        2.36935755e-03,  8.20433217e-03,  1.36164127e-02, -3.10608157e-03,\n",
       "        9.95557501e-03,  8.41067811e-03, -7.56011678e-03, -4.66227507e-02,\n",
       "       -4.09937936e-02,  1.83787480e-02, -3.84925168e-02, -6.71423588e-02,\n",
       "        3.05127477e-02,  1.33795560e-02, -3.59233688e-02, -8.79740309e-02,\n",
       "       -5.08059642e-02,  7.78237765e-02, -3.00221190e-02, -2.82387802e-02,\n",
       "       -4.05229144e-02,  4.76151905e-02, -3.17507227e-02, -8.16052063e-02,\n",
       "        3.92763473e-02,  1.69104341e-02,  1.37344519e-03,  3.25014393e-02,\n",
       "        1.12187686e-02,  1.11415611e-02,  4.67596583e-02,  1.20753362e-02,\n",
       "        8.48933472e-04,  1.36629423e-02,  2.19315825e-02, -1.65352749e-02,\n",
       "       -9.18350038e-02,  4.31459783e-03,  3.28878276e-02, -3.44388008e-02,\n",
       "        6.76570029e-03,  8.88250446e-03,  3.57459802e-02, -2.43674272e-02,\n",
       "       -9.44492492e-03,  2.37181934e-02,  3.53496471e-02, -2.48567364e-03,\n",
       "       -2.55287146e-02,  1.01668049e-02,  6.91051514e-03, -3.57493748e-04,\n",
       "       -6.08793699e-02,  2.26734401e-02, -6.13848809e-03, -5.82940853e-02,\n",
       "       -9.55078849e-02, -8.38179209e-02,  4.62793974e-05,  5.90473006e-02,\n",
       "        3.31346534e-02,  1.38601471e-02,  1.65996809e-02,  7.09885724e-03,\n",
       "       -4.78474440e-02,  2.69545130e-02,  1.60744693e-02, -1.99501976e-02,\n",
       "        5.44556347e-03, -4.52263569e-02, -4.32504482e-02,  5.79264095e-02,\n",
       "       -2.58686489e-02,  7.50790893e-03,  2.01734539e-02,  5.29823393e-03,\n",
       "       -2.04251964e-02,  8.07045004e-03, -2.31031787e-02,  4.58092427e-03,\n",
       "       -2.42804869e-02,  6.74154806e-03,  3.20656572e-02,  1.57483963e-02,\n",
       "        3.29609503e-02,  2.32612869e-04, -1.05993988e-02,  2.77337819e-02,\n",
       "        2.14876136e-03,  3.54487480e-03,  1.44020818e-02, -4.68915454e-02,\n",
       "        1.89558490e-02,  2.23584993e-02,  3.36711668e-03, -2.99664682e-03,\n",
       "       -6.74113130e-03,  2.27636173e-03,  3.74711843e-03, -2.17726530e-02,\n",
       "       -4.44994427e-03,  4.83925138e-02,  1.51265162e-02,  3.27654326e-02,\n",
       "        1.81822483e-02, -9.41332123e-03, -1.43447191e-03, -1.51620982e-02,\n",
       "       -1.72972916e-02,  1.61288076e-02, -4.49084052e-03,  3.67969487e-04,\n",
       "        1.55182605e-02,  6.47362188e-03, -1.38705585e-02,  1.03021438e-02,\n",
       "        2.10469732e-03, -6.96358214e-03, -5.23351074e-02,  2.10757679e-02,\n",
       "        2.27880910e-02,  4.09759241e-02,  8.98526416e-03, -1.91593503e-02,\n",
       "       -2.11049498e-03, -2.41667361e-02,  1.42327304e-02,  1.59125792e-03,\n",
       "        5.89119573e-04,  1.88251894e-02,  1.73116887e-02, -1.51229899e-02,\n",
       "        3.10864719e-02,  2.29973225e-02,  2.24826533e-02, -6.84340621e-03,\n",
       "       -6.99239835e-03, -1.19071646e-04,  2.52917797e-03, -2.69850226e-02,\n",
       "        1.20121672e-02,  1.21115343e-02, -1.64237560e-02])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(r_log,weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.013541684048512628"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(r.loc[\"2015-01-06\",:],weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000413.XSHE</th>\n",
       "      <th>000001.XSHE</th>\n",
       "      <th>000063.XSHE</th>\n",
       "      <th>002007.XSHE</th>\n",
       "      <th>000002.XSHE</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.014977</td>\n",
       "      <td>0.057862</td>\n",
       "      <td>0.051833</td>\n",
       "      <td>-0.036887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.019011</td>\n",
       "      <td>-0.019888</td>\n",
       "      <td>-0.018150</td>\n",
       "      <td>-0.009051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.033598</td>\n",
       "      <td>0.014205</td>\n",
       "      <td>0.020540</td>\n",
       "      <td>-0.044976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.008019</td>\n",
       "      <td>-0.022010</td>\n",
       "      <td>-0.011214</td>\n",
       "      <td>-0.010299</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            000413.XSHE  000001.XSHE  000063.XSHE  002007.XSHE  000002.XSHE\n",
       "date                                                                       \n",
       "2015-01-05          NaN          NaN          NaN          NaN          NaN\n",
       "2015-01-06          0.0    -0.014977     0.057862     0.051833    -0.036887\n",
       "2015-01-07          0.0    -0.019011    -0.019888    -0.018150    -0.009051\n",
       "2015-01-08          0.0    -0.033598     0.014205     0.020540    -0.044976\n",
       "2015-01-09          0.0     0.008019    -0.022010    -0.011214    -0.010299"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r[0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r[1:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.031286770155046696"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(np.dot(r[1:5],weights))#区间收益率是否能这样算？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## classwork2\n",
    "\n",
    "* 继续求组合年化连续收益率（weights=[0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253]）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights=[0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "#ln(p2/p1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "symbol\n",
       "SZSE.000001   -0.0986\n",
       "SZSE.000002    0.5269\n",
       "SZSE.000063    0.1712\n",
       "SZSE.000413    0.0822\n",
       "SZSE.002007    0.2977\n",
       "dtype: float64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "symbol\n",
       "SZSE.000001   -0.0986\n",
       "SZSE.000002    0.5269\n",
       "SZSE.000063    0.1712\n",
       "SZSE.000413    0.0822\n",
       "SZSE.002007    0.2977\n",
       "dtype: float64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#年化连续收益率\n",
    "r_log.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20220850953136035"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(r_log.sum(),weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sz000413    0.177968\n",
       "sz000063    0.171404\n",
       "sz002007    0.297880\n",
       "sz000001   -0.098339\n",
       "sz000002    0.526930\n",
       "dtype: float64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights=np.array([0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.15139075764544993"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 组合风险与协方差矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>symbol</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>SZSE.000001</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0005</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0004</td>\n",
       "      <td>0.0004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SZSE.000002</th>\n",
       "      <td>0.0005</td>\n",
       "      <td>0.0009</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0003</td>\n",
       "      <td>0.0003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SZSE.000063</th>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0015</td>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SZSE.000413</th>\n",
       "      <td>0.0004</td>\n",
       "      <td>0.0003</td>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0016</td>\n",
       "      <td>0.0007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SZSE.002007</th>\n",
       "      <td>0.0004</td>\n",
       "      <td>0.0003</td>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0013</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol       SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "symbol                                                                      \n",
       "SZSE.000001       0.0008       0.0005       0.0006       0.0004       0.0004\n",
       "SZSE.000002       0.0005       0.0009       0.0006       0.0003       0.0003\n",
       "SZSE.000063       0.0006       0.0006       0.0015       0.0008       0.0008\n",
       "SZSE.000413       0.0004       0.0003       0.0008       0.0016       0.0007\n",
       "SZSE.002007       0.0004       0.0003       0.0008       0.0007       0.0013"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.cov()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r4[\"sz000063\"].var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights = np.random.random(5)\n",
    "weights = weights/np.sum(weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights=np.array([0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.04064377223318907"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(np.dot(weights.T, np.dot(r4.cov()*252, weights)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.43039645517311975"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(np.dot(weights.T, np.dot(r.cov()*252, weights)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## classwork3\n",
    "\n",
    "\n",
    "* 组合风险和组合夏普率\n",
    "\n",
    "* 继续求组合年化连续收益率（weights=[0.1484967 , 0.25120513, 0.29997291, 0.26109273, 0.03923253]）\n",
    "\n",
    "* 循环生成100个随机的权重分配方案，并基于连续收益率r_log，计算出各个方案对应的组合连续收益率和组合风险，并以组合风险为横轴，组合收益为纵轴作散点图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2522897688918599"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(data.iloc[-1]/data.iloc[0]-1,weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5861799414458015"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.2522897688918599/0.43039645517311975"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "weights = np.random.random(5)\n",
    "weights = weights/np.sum(weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.20220850953136038"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(r_log,weights).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.43483717056996674"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(np.dot(weights.T, np.dot(r_log.cov()*252, weights)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=[]\n",
    "y=[]\n",
    "for i in range(10000):\n",
    "    weights = np.random.random(5)\n",
    "    weights = weights/np.sum(weights)\n",
    "    y.append(np.dot(r_log,weights).sum())\n",
    "    x.append(np.sqrt(np.dot(weights.T, np.dot(r_log.cov()*252, weights))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1e17e1253c8>]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFW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6fgeuEEJECgM8CeCLEa/+ZUupdoHrSAfitmIzZuc8qAIMAfujY/JCIvCoi34n4trrdMSsAL4nIcRF5wLE99scZwBcAfNe1rWfHuca/FJFpEfk7Ebk1wGt7epw9xlwnbuezz5i7fj73i6CLZpvbr/k4gD9RSlVaeG0naGfM1TcQuQbVqPJhpdSvapv/EsDNADYAeBfAN6IYrP2Rmm1hxrxZKfUxAHcC+EMR+dcRjs1EFMd5MYDPAHjOsbnXx/lHqKZ/1gP4HwDGQ7y2E7Qz5uobxPN89hpz18/nfhH0MwBudDy+AcBZ1z5DAJ4RkbcA3APgL0Rk2Oe1PxeR6wCg9m/QFEKnxwwRsVA9+Z9WSn3PfoFS6udKqYpSagHA/0T1tjIWY1ZKna39+wsAf+sYW2yPc407AfxIKfVze0Ovj7NS6ldKqd/Ufn8RgCUi1/q8tqfH2WPMsT2fvcbck/O5E5MJcftBtXfqGwBW48rkxq0e+/8VrkwwGl8LYB8aJzf+PCZjFgB/A+BxzX7XOX7fDeCZmIz5agAfcPz+MoA74nycHdueAfAHcTrOAD6MKwsHbwdwunZexPZ89hhzbM9njzH35nyO6o3i/gPgLlRnx18H8J9r2x4E8KBm34Yvre61te0fAvAPAP6x9u/yOIwZwCdRvTV8FcBU7eeu2nP/C8BrtecOOr8QPR7zR2pfmGkAM0k4zrXHAwB+CWCpa7+eHmcAD9WO4zSAYwD+VdzPZ9OY43w+e4y5J+czl/4TQkhK6JccOiGEpB4KOiGEpAQKOiGEpAQKOiGEpAQKOiGEpAQKOiGEpAQKOiGEpIT/D6fYWXwa0zJ/AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x,y,\"o\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>symbol</th>\n",
       "      <th>SZSE.000001</th>\n",
       "      <th>SZSE.000002</th>\n",
       "      <th>SZSE.000063</th>\n",
       "      <th>SZSE.000413</th>\n",
       "      <th>SZSE.002007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eob</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-06</th>\n",
       "      <td>-0.0151</td>\n",
       "      <td>-0.0376</td>\n",
       "      <td>0.0563</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-07</th>\n",
       "      <td>-0.0192</td>\n",
       "      <td>-0.0091</td>\n",
       "      <td>-0.0201</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0183</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-08</th>\n",
       "      <td>-0.0342</td>\n",
       "      <td>-0.0460</td>\n",
       "      <td>0.0141</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-09</th>\n",
       "      <td>0.0080</td>\n",
       "      <td>-0.0104</td>\n",
       "      <td>-0.0223</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-01-12</th>\n",
       "      <td>-0.0208</td>\n",
       "      <td>-0.0248</td>\n",
       "      <td>-0.0212</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-25</th>\n",
       "      <td>0.0057</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0058</td>\n",
       "      <td>-0.0043</td>\n",
       "      <td>-0.0057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-28</th>\n",
       "      <td>-0.0353</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0348</td>\n",
       "      <td>-0.0337</td>\n",
       "      <td>-0.0187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-29</th>\n",
       "      <td>0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0135</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-30</th>\n",
       "      <td>0.0008</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0286</td>\n",
       "      <td>0.0130</td>\n",
       "      <td>0.0107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-12-31</th>\n",
       "      <td>-0.0091</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>-0.0275</td>\n",
       "      <td>-0.0229</td>\n",
       "      <td>-0.0247</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>243 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "symbol      SZSE.000001  SZSE.000002  SZSE.000063  SZSE.000413  SZSE.002007\n",
       "eob                                                                        \n",
       "2015-01-06      -0.0151      -0.0376       0.0563       0.0000       0.0505\n",
       "2015-01-07      -0.0192      -0.0091      -0.0201       0.0000      -0.0183\n",
       "2015-01-08      -0.0342      -0.0460       0.0141       0.0000       0.0203\n",
       "2015-01-09       0.0080      -0.0104      -0.0223       0.0000      -0.0113\n",
       "2015-01-12      -0.0208      -0.0248      -0.0212       0.0000       0.0207\n",
       "...                 ...          ...          ...          ...          ...\n",
       "2015-12-25       0.0057       0.0000       0.0058      -0.0043      -0.0057\n",
       "2015-12-28      -0.0353       0.0000      -0.0348      -0.0337      -0.0187\n",
       "2015-12-29       0.0091       0.0000       0.0135       0.0143       0.0398\n",
       "2015-12-30       0.0008       0.0000       0.0286       0.0130       0.0107\n",
       "2015-12-31      -0.0091       0.0000      -0.0275      -0.0229      -0.0247\n",
       "\n",
       "[243 rows x 5 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x1cd7e395cc8>]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAud0lEQVR4nO2dfZAc5Z3fv78Z9aJZ2aeRzF4Mg2TJhJIKlSwtyIAtV3JS6iwwZVgDRmC4VC5xKKqCEwjZ3HJ2bFHHnde3IXBJ8FHE5dxdrBjJCG/BCZecOqkqVXKJIHm1qGRLZ16FRj5bBi22tQOanX3yx0zP9vQ8T79Nz0v3fD9VKu329PQ8avV8++nv83sRpRQIIYQkn0y3B0AIISQeKOiEEJISKOiEEJISKOiEEJISKOiEEJISFnXrgy+++GK1atWqbn08IYQkkiNHjvxKKTWke61rgr5q1SocPny4Wx9PCC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/dpu1+JBL/1BtRn2awBWY2EhY53H/n+FhcVF43sBTKBxIePPe2jcAuBvADyu2e8Sx88PAHi6h8a9BMAHHT//CMD1vX6+HdueBvCHnTrfQcYM4MNYSCK8BsCp2vXR09e2x7h7+tr2GHfbr+3Y/qG9/gfAZ1BdDX8VwJdr2+4FcK9m34Yvqu69te0fAvB3AH5W+3t5r4wbwKdQfRR8GcDR2p/P1F77XwCO1V57zvkl6IFxf7T2JZkGcDwp57v2+yCAtwEsde3X1vPtN2YA99XO5TSAQwA+mYRr2zTuXr+2Pcbd9mubqf+EEJIS+sVDJ4SQ1ENBJ4SQlEBBJ4SQlEBBJ4SQlEBBJ4SQlEBBJ4SQlEBBJ4SQlPD/AYr+zjFIxpWFAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(fx,sy,\"o\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基于scipy.optimizet 的组合投资优化方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "def min_sharpe(weights):\n",
    "    \n",
    "    weights = weights/np.sum(weights)\n",
    "    z_r=np.sum(np.dot(r_log,weights))\n",
    "    z_f=np.sqrt(np.dot(weights.T, np.dot(r_log.cov()*252, weights)))\n",
    "\n",
    "    return z_f/z_r#optimize是去最小值，所以这里用夏普率的倒数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.233350945279795"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min_sharpe(weights)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.optimize as sco"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "#help(sco)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: 0.8939093390318993\n",
       "     jac: array([ 7.92866424e-01,  5.91501594e-05,  4.12997700e-01,  3.19267094e-01,\n",
       "       -3.01726162e-04])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 36\n",
       "     nit: 6\n",
       "    njev: 6\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([0.00000000e+00, 8.36158649e-01, 9.91098657e-17, 0.00000000e+00,\n",
       "       1.63841351e-01])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "noa=5\n",
    "#约束是所有参数(权重)的总和为1。这可以用minimize函数的约定表达如下\n",
    "\n",
    "cons = ({'type':'eq', 'fun':lambda x: np.sum(x)-1})\n",
    "\n",
    "#我们还将参数值(权重)限制在0和1之间。这些值以多个元组组成的一个元组形式提供给最小化函数\n",
    "\n",
    "bnds = tuple((0,1) for x in range(noa))\n",
    "\n",
    "#优化函数调用中忽略的唯一输入是起始参数列表(对权重的初始猜测)。我们简单的使用平均分布。\n",
    "\n",
    "opts = sco.minimize(min_sharpe, noa*[1./noa,], method = 'SLSQP', bounds = bnds, constraints = cons)\n",
    "\n",
    "opts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.00000000e+00, 8.36158649e-01, 9.91098657e-17, 0.00000000e+00,\n",
       "       1.63841351e-01])"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opts[\"x\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48934441740385565"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(np.dot(r_log,opts[\"x\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48946330119032233"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(np.dot(r_log,opts[\"x\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.   , 0.   , 0.164, 0.   , 0.836])"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opts['x'].round(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {},
   "outputs": [],
   "source": [
    "#r_log"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48936542038912945"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(np.dot(r_log,opts['x'].round(3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.48930805654399134"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(np.dot(r_log,opts['x'].round(3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## classwork 4\n",
    "\n",
    "上面是看夏普率最大\n",
    "参考：https://zhuanlan.zhihu.com/p/20604930?refer=quantstory\n",
    "找出投资收益率最大的组合权重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "def min_sharpe(weights):\n",
    "    \n",
    "    weights = weights/np.sum(weights)\n",
    "    z_r=np.sum(np.dot(r_log,weights))\n",
    "    return 1/z_r#optimize是去最小值，所以这里用夏普率的倒数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     fun: 1.8979102858143193\n",
       "     jac: array([ 2.2531343 , -0.        ,  1.28129637,  1.60179289,  0.82555868])\n",
       " message: 'Optimization terminated successfully'\n",
       "    nfev: 12\n",
       "     nit: 2\n",
       "    njev: 2\n",
       "  status: 0\n",
       " success: True\n",
       "       x: array([4.71844785e-15, 1.00000000e+00, 2.44249065e-15, 6.43929354e-15,\n",
       "       3.74700271e-15])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "noa=5\n",
    "#约束是所有参数(权重)的总和为1。这可以用minimize函数的约定表达如下\n",
    "\n",
    "cons = ({'type':'eq', 'fun':lambda x: np.sum(x)-1})\n",
    "\n",
    "#我们还将参数值(权重)限制在0和1之间。这些值以多个元组组成的一个元组形式提供给最小化函数\n",
    "\n",
    "bnds = tuple((0,1) for x in range(noa))\n",
    "\n",
    "#优化函数调用中忽略的唯一输入是起始参数列表(对权重的初始猜测)。我们简单的使用平均分布。\n",
    "\n",
    "opts = sco.minimize(min_sharpe, noa*[1./noa,], method = 'SLSQP', bounds = bnds, constraints = cons)\n",
    "\n",
    "opts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.71844785e-15, 1.00000000e+00, 2.44249065e-15, 6.43929354e-15,\n",
       "       3.74700271e-15])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opts[\"x\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5268952950381103"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(np.dot(r_log,opts[\"x\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
